from fastapi_utils.api_model import APIModel
from pydantic import BaseModel, Field, ConfigDict
from datetime import datetime
from typing import Optional, List


class DictTypeOutSchema(APIModel):
    id: int = Field(description="字典类型ID")
    type_name: str = Field(description="字典类型名称", alias="typeName")
    type_code: str = Field(description="字典类型编码", alias="typeCode")
    description: Optional[str] = Field(default=None, description="字典类型描述")
    create_time: datetime = Field(description="创建时间", alias="createTime")
    update_time: datetime = Field(description="更新时间", alias="updateName")
    enable: int = Field(description="是否启用")

    model_config = ConfigDict(from_attributes=True)


class DictDataOutSchema(APIModel):
    model_config = ConfigDict(from_attributes=True)

    id: int = Field(description="字典数据ID", alias="dataId")
    data_label: str = Field(description="字典数据标签", alias="dataLabel")
    data_value: str = Field(description="字典数据值", alias="dataValue")
    remark: Optional[str] = Field(default=None, description="备注")
    enable: int = Field(description="是否启用")


class DictTypeQueryModel:
    def __init__(
        self,
        type_name: Optional[str] = None,
        page: int = 1,
        limit: int = 10,
    ):
        self.type_name = type_name
        self.page = page
        self.limit = limit


class DictTypeSaveModel(APIModel):
    type_name: str = Field(..., description="字典类型名称")
    type_code: str = Field(..., description="字典类型编码")
    enable: int = Field(1, description="是否启用")
    description: Optional[str] = Field(None, description="字典类型描述")


class DictTypeUpdateModel(APIModel):
    id: int = Field(..., description="字典类型ID")
    type_name: str = Field(..., description="字典类型名称")
    type_code: str = Field(..., description="字典类型编码")
    enable: int = Field(..., description="是否启用")
    description: Optional[str] = Field(None, description="字典类型描述")


class DictTypeEnableModel(BaseModel):
    id: int = Field(..., description="字典类型ID")


class DictDataQueryModel:
    def __init__(
        self,
        type_code: Optional[str] = None,
        page: int = 1,
        limit: int = 10,
    ):
        self.type_code = type_code
        self.page = page
        self.limit = limit


class DictDataSaveModel(APIModel):
    data_label: str = Field(..., description="字典数据标签")
    data_value: str = Field(..., description="字典数据值")
    enable: int = Field(1, description="是否启用")
    remark: Optional[str] = Field(None, description="备注")
    type_code: str = Field(..., description="字典类型编码")


class DictDataUpdateModel(APIModel):
    data_id: int = Field(..., description="字典数据ID")
    data_label: str = Field(..., description="字典数据标签")
    data_value: str = Field(..., description="字典数据值")
    enable: int = Field(..., description="是否启用")
    remark: Optional[str] = Field(None, description="备注")
    type_code: str = Field(..., description="字典类型编码")


class DictDataEnableModel(BaseModel):
    dataId: int = Field(..., description="字典数据ID")


class DictTypeBatchRemoveModel(BaseModel):
    ids: List[int] = Field(..., description="字典类型ID列表")


class DictDataBatchRemoveModel(BaseModel):
    ids: List[int] = Field(..., description="字典数据ID列表")
